<template lang="html">
  <div class="login-main">
    <div class="login-logo"></div>
    <div class="login-content">
      <div class="login-username">
        <i class="iconfont icon-zhanghao"></i>
        <input type="text" v-model='username' value="" placeholder="手机号">
      </div>
      <div class="login-password">
        <i class="iconfont icon-lock"></i>
        <input type="text" v-model='password' placeholder="密码至少包含字母，数字，且不少于8位">
      </div>
      <p v-if="errorTips" class="error-tips">用户名或密码错误，请重新输入</p>
      <div class="login-btn">
        <button type="button"  name="button"  @click='loginClick'>登录</button>
      </div>
      <p class="forget-psw">忘记密码？</p>
    </div>

  </div>
</template>

<script>
export default {
  name:'LoginMain',
  data(){
    return{
      username:'',
      password:'',
      errorTips:false
    }
  },
  props:{
    userInfo:{
      type:Object,
      default:function(){
        return{}
      }
    }
  },
  methods:{
    loginClick(event){
      if(!(/^1[34578]\d{9}$/.test(this.username))){
        this.errorTips = true
        setTimeout(() => {
            this.errorTips = false
        },1000)
        return;
        console.log('输入有误');
      }else if(!(/^(?=.*[a-z])(?=.*\d)[^]{8,16}$/i.test(this.password))){
        this.errorTips=true
        setTimeout(() => {
            this.errorTips = false
        },1000)
        return;
        console.log('输入有误');
      }
      this.$emit('sendUserInfo',{
          username:this.username,
          password:this.password
        })
    }
  }
}
</script>

<style lang="less" scoped>
.login-main{
  .login-logo{
    width: 1.93rem;
    height: 1.93rem;
    margin: 0.65rem auto;
    background: url('../../assets/img/MineLogo.png') no-repeat;
    background-size: cover;
  }
  .login-content{
    position: relative;
    .login-username,.login-password{
      width: 5.92rem;
      height: 0.47rem;
      margin: 0 auto;
      margin-bottom: 0.65rem;
      border-bottom: 0.02rem solid #43bf92;
      input{
        font-size: 0.3rem;
        height: 80%;
        width: 90%;
        outline: none;
      }
    }
    .error-tips{
      position: absolute;
      width: 3.92rem;
      height: 0.6rem;
      line-height: 0.6rem;
      color: 	#fff;
      background: rgba(0,0,0,.4);
      left: 50%;
      margin-left: -1.96rem;
      top: 0.6rem;
    }
    .login-btn{
      width: 100%;
      margin-top: 1.56rem;
      text-align: center;
      button{
        font-size: 0.3rem;
        color: #fff;
        width: 5.11rem;
        height: 0.75rem;
        border: 0.02rem solid #44bf91;
        background-color: #44bf91;
        border-radius: 0.1rem;
        outline: none;
      }
    }
    .forget-psw{
      width: 5.11rem;
      margin: 0.2rem auto;
      text-align: right;
    }
  }

}
</style>
